home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 128 31 / q31.d81 / t.128 rle < prev    next >
Text File  |  2022-08-28  |  15KB  |  376 lines

  1.  
  2.  
  3.                                1 2 8    R L E
  4.  
  5.                           Program by Bob Markland
  6.  
  7.                     Text by Bob Markland and Jeff Jones
  8.  
  9.  
  10.     For several months now RLE file compression has been used to cram up to
  11. 35% more programs and text onto each issue of LOADSTAR 64.  To accomplish
  12. this feat, Jeff Jones wrote a RLE -- Run Length Encoding -- utility,
  13. published on LS #134.
  14.  
  15.     Recently, Fender sent me Jeff's M/L source code along with a request to
  16. make it work on the C-128.  After some discussion, Fender and I agreed that
  17. Jeff's program did everything he wanted it to, just not in 128 mode.  So,
  18. if you happen to subscribe to both LOADSTAR 64 and LOADSTAR 128 you will
  19. find that 128 RLE works much the same as the C-64 version.  (I have a real
  20. aversion to re-inventing the wheel).
  21.  
  22.     It will pay you, though, to become familiar with the following
  23. information because BANK selection and differences in syntax are important
  24. considerations on the C-128.
  25.  
  26.     RLE is probably the most simple form of data compression next to
  27. tokenization.  It encodes repetitious data in only two bytes instead of up
  28. to 128.  RLE uses 4 bytes to encode 256 repeating bytes.  In the code, the
  29. first byte says how many consecutive bytes to expect.  The second byte is
  30. the actual byte that's being repeated.  So 500 consecutive zeroes are coded
  31. as 8 bytes instead of 500.
  32.  
  33.     We could code up to 255 bytes, but it's more efficient to use only the
  34. lower 128 numbers for repeating characters and the higher 127 for non-
  35. repeating data.  That way we don't have to have terminating flags, which
  36. could possibly take up a lot of room if packing a big file.  Thus, we have
  37. a method by which the same byte that would flag repeating characters can be
  38. used to flag an upcoming stream of non-repeating data.  Streams of data
  39. that don't repeat are preceded by a byte that is 128 plus the number of
  40. non-repeating characters.  The machine language easily spots literals and
  41. then subtracts 128 from the code.
  42.  
  43.     RLE works extremely well with fonts and most hi-res graphics.  You
  44. wouldn't want to use RLE on text unless it was full of consecutive spaces
  45. or other repeating characters.
  46.  
  47.     When used in conjunction with a screen switcher, RLE also works well
  48. with program and game screens because, except for text screens like the one
  49. you're reading now, most screens are full of consecutive spaces.  Otherwise
  50. they'd look too crowded.  So most lend themselves to RLE.  And even if the
  51. screen doesn't pack well, the color memory of a text screen, even if it
  52. varies from line to line, is usually laid out in such a way that the 1000
  53. color bytes would pack down to only a few bytes.  (See "Jeff's Tutorial on
  54. Packing Screens" below).
  55.  
  56.     Heavily dithered, "misty" and "busy" graphics, such as the type created
  57. by Walt Harned, won't pack as well with RLE as they would with other forms
  58. of compression, though they usually pack somewhat.   Basically, the more
  59. you see solid, unobstructed blocks of pixels or color, the more packable
  60. that graphic is.
  61.  
  62.  
  63.  USING 128/RLE
  64.  -------------
  65.  
  66.     There are three versions of 128/RLE on the disk:
  67.  
  68.       FILENAME      SYS LOCATION
  69.       --------------------------
  70.       128/RLE 0C00     3072
  71.       128/RLE 1300     4864
  72.       128/RLE 1C00     7168
  73.  
  74.  NOTE: The source code to the routine (in EBUD format) is on the disk in
  75. the file, "128/rle.s".
  76.  
  77.     Load any one of these files into BANK 0, using:
  78.  
  79.   BLOAD"128/RLE xxxx",Un,B0,Pnnnn
  80.  
  81.     Which version above is the best one for you to use in a program?  That
  82. depends on the other ML programs or routines that you might want to use.
  83. The first two ($0C00 and $1300) can be used as long as you aren't using
  84. that area for other ML routines.  The code at $1C00 requires that you open
  85. up the graphic area ($1C00-$4000) with a GRAPHIC1 command.
  86.  
  87.  FENDER'S NOTE: Since I program only in the 80-column mode on 128
  88. computers, and invariably use CONTROL80, my programs always have
  89. BASIC moved up to $4000 with a GRAPHIC1 command.  This gives me the area
  90. from $1C00 to $4000 for storing screens, data, or even machine language
  91. routines like 128 REL.
  92.  
  93.     In all the examples 128/RLE observes the following conventions. You
  94. will note that they closely parallel BASIC 7.0 commands such as BLOAD and
  95. BSAVE, with two major exceptions:
  96.  
  97.  (1) You MUST follow the SYS command with a colon (:) rather than a comma.
  98.  
  99.  (2) Unlike BASIC 7.0 there are no default values.  You MUST supply ALL
  100. drive (U), bank (B), and address (P) information, as shown in the examples
  101. below.
  102.  
  103.  SYSADDR[+N]:A,B$,C
  104.  
  105.     ADDR[+N]: is the LOAD address of the M/L module plus N if applicable.
  106. A, B$ and C are parameters.  Parameters followed by $, such as B$, can be
  107. supplied in string variables or literals within quotes or a combination of
  108. the two, or any algorithm that creates a string.  Numeric parameters can be
  109. replaced with variables.  NO QUOTES!!!  You may also use any formula or
  110. equation that generates a positive integer.
  111.  
  112.  IMPORTANT NOTE:  If you choose to use string variables, a combination of
  113. string and literal text in quotes, or numeric variables, they MUST be
  114. enclosed in parentheses ().
  115.  
  116.  
  117.  PACKING A FILE
  118.  --------------
  119.  
  120.  SYSADDR+3:FILE$,U1,B1,P1:DEST$,U2,P2
  121.  
  122.     This command will BLOAD a file to a buffer which you specify and pack
  123. it, then SAVE the packed file under a new filename on any active drive,
  124. with any LOAD address you desire.
  125.  
  126.   ADDR+3 is the location of the pack file code.
  127.  
  128.   FILE$ is the parameter where you plug in the filename.  Since this isn't
  129. an archive utility, and the packed files are meant to be used in memory,
  130. the file must be small enough to fit into memory.
  131.  
  132.   U1 is the device number of the source drive.
  133.  
  134.   B1 is the bank where the source file will be loaded.
  135.  
  136.   P1 is the area where the file will be examined by 128/RLE.  When you pack
  137. from disk file to disk file you will no doubt use the "RLE DISK TO DISK"
  138. BASIC program included on this disk (and explained later) or your own
  139. embellished version, which will probably be very short.  So you can select
  140. a buffer at any address in BANK 0, following the BASIC program.
  141.  
  142.   This can be as low as 8192, which gives you room for a buffer of 223
  143. blocks ($2000-$FEFF).  Address 16384+ ($4000+) in BANK 1 is used as the
  144. default output buffer.  However, you can select any area of BANK 1, if you
  145. find a need, by entering:
  146.  
  147.   POKESYS+18,page.
  148.  
  149.   For example: POKESYS+18,32 lowers the beginning of the buffer to 8192 in
  150. BANK 1.  If you find BANKing a little confusing, note that a graphic file
  151. being examined at 8192 in BANK 0 and the output buffer at 8192 in BANK 1 do
  152. not interfere with one another.  You can even select a buffer directly
  153. under 128/RLE.
  154.  
  155.   DEST$ is the filename of your destination file.
  156.  
  157.   U2 is the device number of your destination drive.
  158.  
  159.   P2 is the desired LOAD address of the packed file.
  160.  
  161.  
  162.  UNPACKING FILES
  163.  ---------------
  164.  
  165.     Files can be unpacked in one of two ways.  Packed files can be BLOADED
  166. into a buffer by a routine in your program and then unpacked from one
  167. location to another or they can be unpacked straight from disk with the
  168. following command:
  169.  
  170.  SYSADDR:FILE$,Un,Bn,Pn
  171.  
  172.    FILE$ is the filename of the packed file.
  173.  
  174.    Un is the device number of the drive containing the file you wish to
  175. unpack.
  176.  
  177.    Bn is the bank number to which the file is to be loaded (usually 1 or
  178. 0).
  179.  
  180.    Pn is the desired LOAD address of the data.  Making this parameter 0
  181. will cause the unpack routine to respect the LOAD address the file was
  182. created with.
  183.  
  184.  
  185.  COMPRESS RANGE OF MEMORY
  186.  ------------------------
  187.  
  188.  SYSADDR+6:B1,P1,P2,B2,P3
  189.  
  190.     Here you can compress any range of memory and stash the compressed data
  191. anywhere in RAM.  This is useful if you already have data in memory which
  192. you want to compress.  Locations 253 and 254 or F% will report the end of
  193. the output buffer, which you will need to know if you want to BSAVE the
  194. data.  If F% is a negative number (integer variables only go up to 32768),
  195. you can derive the end from PEEK(254)*256+PEEK(253).
  196.  
  197.   B1 is the bank where the decompressed data resides.
  198.  
  199.   P1 is the beginning address of the decompressed data.
  200.  
  201.   P2 is the ending address of the data to be packed PLUS 1 (+1).
  202.  
  203.   B2